package com.zpark.resp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.zpark.resp
 * @ClassName: ResposeServlet01
 * @Description:
 * @author: RZS
 * @date: 2024/12/10  17:34
 */
@WebServlet("/qs1.do")
public class ResponseServlet01 extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		/*
			response常用方法
		 */
		// 响应头常用方法
		// resp.setStatus(500); // 设置响应状态码
		// resp.sendError(500, "用户不存在"); // 设置错误状态码

		// 响应行常用方法
		/*
		 * 添加响应头,并设置响应头值
		 */
		resp.addHeader("dc", "大锤");
		/*
		 * 添加响应头，并设置响应头值
		 */
		resp.addIntHeader("age", 18);
		/*
		 * 设置响应头，并设置响应头值
		 */
		resp.setHeader("name", "小明");

		/*
		 * 设置响应体类型
		 */
		resp.setContentType("text/html;charset=utf-8");
		/*
		 * 设置响应体长度
		 */
		resp.setContentLength(1024);

	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

	}
}
